package cn.good.yan.controller;

import cn.good.yan.service.T1Service;
import cn.hutool.core.util.IdUtil;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 演示：正常的请求
 * 在高并发的情况下，hystrix的正常请求，都需要延迟，才响应
 *  1 、 2 服务降级处理
 *  3  服务熔断处理
 * @author shengren.yan
 * @create 2023-12-27
 */
@RestController
@RequestMapping("/t1")
@Slf4j
public class T1Controller {

    @Autowired
    private T1Service service;

    @Value("${server.port}")
    private String serverPort;

    // 1 正常的请求
    @GetMapping("/hystrix/{id}")
    public String paymentInfoOk(@PathVariable("id") Integer id) {
        String result = service.paymentInfoOk(id);
        log.info("****result: " + result);
        return result;
    }

    // 2 延迟的请求 - 延迟5分钟进行响应
    @GetMapping("/hystrix/timeout/{id}")
    public String paymentInfoTimeOut(@PathVariable("id") Integer id) throws InterruptedException {
        String result = service.paymentInfoTimeOut(id);
        log.info("****result: " + result);
        return result;
    }

    // 3 服务熔断
    @GetMapping("/hystrix/circuit/{id}")
    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
        String result = service.payBreaker(id);
        log.info("****result: " + result);
        return result;
    }



}
